package org.ztr.saa01helloword.controller;

import jakarta.annotation.Resource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/9/24 21:38
 * @Description:  LLM控制器
 * @Version: 1.0
 */
@RestController
@RequestMapping("/ai")
public class SaaLLMController {
    private static final Logger logger = LogManager.getLogger(SaaLLMController.class);

    @Resource
    private ChatModel chatModel;

    /**
     * 通用调用
     * @param msg
     * @return
     */
    @GetMapping("/hello/doChat")
    public String doChat(@RequestParam(name = "msg", defaultValue = "你是谁") String msg) {
        String result = chatModel.call(msg);
        return result;
    }

    /**
     * 流式调用
     * @param msg
     * @return
     */
    @GetMapping("/hello/streamChat")
    public Flux<String> stream(@RequestParam(name = "msg", defaultValue = "你是谁") String msg) {
        return chatModel.stream(msg);
    }
}
